<?php
namespace API\Controller;
use Think\Controller;
class UserserviceController extends Controller {
  public function login(){
    	$user_name=$_GET['user_name'];
    	$user_password=$_GET['user_password'];
    	$userModel=M('user'); //实例化模型对象 user 表名
		  $user=$userModel->where("user_name='$user_name' and user_password='$user_password'")->field('user_id')->select(); //查询
      echo json_encode($user);
    }
    public function regist(){
      $user_name=$_GET['user_name'];
      $user_password=$_GET['user_password'];
      $user_tel=$_GET['user_tel'];
      $user_email=$_GET['user_email'];
      $user_picture=$_GET['user_picture'];
      $userModel=M('user');
      $data=$userModel->create();
      $map['user_name']=$user_name;
      $map['user_tel']=$user_tel;
      $count = $userModel->where($map)->getField('count(*)');
      if($count>0){
        //已经收藏
        $success = '2';
        $error_code='已注册';
      }else{
        $data['user_name']=$user_name;
        $data['user_password']=$user_password;
        $data['user_tel']=$user_tel;
        $data['user_email']=$user_email;
        $data['user_picture']=$user_picture;
        $data['user_date']=date('Y-m-d H:i:s');
        $res=$userModel->data($data)->add();
        if($res){
          //收藏成功
          $success='1';
          $error_code='注册成功';
        }else{
          //收藏失败
          $success='0';
          $error_code='注册失败';
        }
      }
      $json=array('success' =>$success, 'error_code' =>$error_code, 'datalist' =>$datalist);
      echo json_encode($json);
    }
    public function getUserpost(){
       $user_id=$_GET['user_id'];
       $postModel=M('post');
       $info=$postModel->where("user_id='$user_id'")->select();
       echo json_encode($info);
    }

    public function getUserattention(){
       $user_id=$_GET['user_id'];
       $attentionModel=M('attention');
       $info=$attentionModel->where("user_id='$user_id'")->select();
       echo json_encode($info);
    }

    public function getUserorder(){
      $user_id=$_GET['user_id'];
      $orderModel=M('order');
      $info=$orderModel->where("user_id='$user_id'")->select();
      echo json_encode($info);
    }
    
    public function getUserorderbyId(){
      $order_id=$_GET['order_id'];
      $orderModel=M('order');
      $info=$orderModel->where("order_id='$order_id'")->select();
      echo json_encode($info);
    }
}